﻿Imports SIGI.Common.BE
Imports System.Data.SqlClient
Imports System.Configuration

Public Class Profiles_ScreensDAC

#Region "<< -SearchByParams- >>"
    Public Shared Function SearchByParams(pProfile_ScreenBE As Profile_ScreenBE) As List(Of Profile_ScreenBE)
        Dim wSqlConn As SqlConnection = Nothing
        Dim wSqlCmd As SqlCommand = Nothing
        Dim wReader As SqlDataReader = Nothing
        Dim wConnStr As String = String.Empty

        Dim wProfile_ScreenBE As Profile_ScreenBE = Nothing
        Dim wProfile_ScreenBEList As List(Of Profile_ScreenBE) = Nothing

        Try
            'Obtengo la cadena de conexión
            wConnStr = ConfigurationManager.ConnectionStrings("connString").ConnectionString
            'Creo la conexión a la BD
            wSqlConn = New SqlConnection(wConnStr)
            'Creo el comando
            wSqlCmd = New SqlCommand()
            wSqlCmd.Connection = wSqlConn
            wSqlCmd.CommandType = CommandType.StoredProcedure
            wSqlCmd.CommandText = "PerfilesxPantalla_s_ByParams"

            wSqlCmd.Parameters.Add("@ID_Perfil", SqlDbType.Int)
            wSqlCmd.Parameters.Add("@ID_Pantalla", SqlDbType.Int)
            wSqlCmd.Parameters.Add("@ID_Permiso", SqlDbType.Int)

            If pProfile_ScreenBE.IdProfile.HasValue Then
                wSqlCmd.Parameters("@ID_Perfil").Value = pProfile_ScreenBE.IdProfile.Value
            End If
            If pProfile_ScreenBE.IdScreen.HasValue Then
                wSqlCmd.Parameters("@ID_Pantalla").Value = pProfile_ScreenBE.IdScreen.Value
            End If
            If pProfile_ScreenBE.IdPermission.HasValue Then
                wSqlCmd.Parameters("@ID_Permiso").Value = pProfile_ScreenBE.IdPermission.Value
            End If

            wSqlConn.Open()
            wReader = wSqlCmd.ExecuteReader()

            wProfile_ScreenBEList = New List(Of Profile_ScreenBE)
            While wReader.Read()
                wProfile_ScreenBE = New Profile_ScreenBE

                wProfile_ScreenBE.IdProfile = Convert.ToInt32(wReader("ID_Perfil"))
                wProfile_ScreenBE.IdScreen = Convert.ToInt32(wReader("ID_Pantalla"))
                wProfile_ScreenBE.IdPermission = Convert.ToInt32(wReader("ID_Permiso"))

                wProfile_ScreenBEList.Add(wProfile_ScreenBE)
            End While
            wSqlConn.Close()
        Catch ex As Exception
            Throw ex
        End Try

        Return wProfile_ScreenBEList
    End Function
#End Region

End Class
